import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class InterfaceService {

  constructor(public httpClient: HttpClient) { }
  private root_url="http://192.168.100.51:8090/";


  //桌面图标
  getAllIcon(): Observable<any> {
    return this.httpClient.get(this.root_url + 'oa-service/getAllIcon.php');
  }

  //办公用品申请
  // getAllGoods(): Observable<any> {
  //   return this.httpClient.get('http://192.168.100.100:8066/oa-service/getAllGoods.php');
  // }

  //办公用品栏目
  getAllGoodstype(): Observable<any> {
    return this.httpClient.get(this.root_url + 'oa-service/getAllGoodstype.php');
  }
  //登录
  getLogin(name: any, password: any): Observable<any> {
    let formdata = new FormData();
    formdata.append('name', name);
    formdata.append('password', password);
    return this.httpClient.post(this.root_url + 'oa-service/getLogin.php', formdata);
  }


  //修改密码
  editPassword(id: any, password: any): Observable<any> {
    let formdata = new FormData();
    formdata.append('id', id);
    formdata.append('password', password);
    return this.httpClient.post(this.root_url + 'oa-service/resetPassword.php', formdata);
  }

  //获取所有员工
  getEmployee(): Observable<any> {
    return this.httpClient.get(this.root_url + "oa-service/getAllEmployee.php");
  }
  //查看员工个人信息
  // getEmployeeId():Observable<any>{
  //   return this.httpClient.post(this.get)
  // }

  //上班打卡
  inserAttendence(empid): Observable<any> {
    let formdata = new FormData();
    formdata.append('id', empid);
    return this.httpClient.post(this.root_url + "oa-service/getAttendence.php", formdata);
  }

  //下班打卡
  inserAttendenceOff(empid): Observable<any> {
    let formdata = new FormData();
    formdata.append('id', empid);
    return this.httpClient.post(this.root_url + "oa-service/getAttendenceOff.php", formdata);
  }

  //迟到
  lateForWork(year, month, empid): Observable<any> {
    let formdata = new FormData();
    formdata.append('year', year);
    formdata.append('month', month);
    formdata.append('id', empid);

    return this.httpClient.post(this.root_url + "oa-service/getLateWork.php", formdata);

  }



  //获取任务分类
  taskCategory(): Observable<any> {
    return this.httpClient.get(this.root_url + 'oa-service/getCategories.php');
  }

  //获取发布任务中的项目参与人
  taskAttend(): Observable<any> {
    return this.httpClient.get(this.root_url + 'oa-service/getAllEmployee.php');
  }

  //发布任务
  releaseTask(title, content, categories, publisher, submitter, time, issued, remark): Observable<any> {

    let formdata = new FormData();
    formdata.append('title', title);
    formdata.append('content', content);
    formdata.append('categories', categories);
    formdata.append('publisher', publisher);
    formdata.append('submitter', submitter);
    formdata.append('time', time);
    formdata.append('issued', issued);
    formdata.append('remark', remark);

    return this.httpClient.post(this.root_url + 'oa-service/insertTask.php', formdata);
  }

  //获取薪资
  getAllSalary(yaer = '2019', month = '11'): Observable<any> {
    let formdata = new FormData();
    formdata.append('year', yaer);
    formdata.append('month', month);
    return this.httpClient.post(this.root_url + 'oa-service/getAllSalary.php', formdata)
  }

  //修改个人资料
  resetPerson(id: any, phone: any, address: any, email: any): Observable<any> {
    let formdata = new FormData();
    formdata.append('id', id);
    formdata.append('phone', phone);
    formdata.append('address', address);
    formdata.append('email', email);
    return this.httpClient.post(this.root_url + 'oa-service/resetPerson.php', formdata);
  }

  //获取未完成的任务



  //通讯录
  getDeptMember(): Observable<any> {
    return this.httpClient.get(this.root_url + "oa-service/getDeptMember.php");
  }
  //添加商品
  insertCart(goodId, empId): Observable<any> {
    let formdata = new FormData();
    formdata.append("goodId", goodId);
    formdata.append("empId", empId);
    return this.httpClient.post(
      this.root_url + "oa-service/insertCart.php",
      formdata
    );
  }

  //查看个人信息(人事管理)
  getPersonalInfo(id: any): Observable<any> {
    return this.httpClient.get(this.root_url + "oa-service/getEmployeeId.php", { params: { id } });
  }

  //获取所有部门
  getAllDept(): Observable<any> {
    return this.httpClient.get(this.root_url + "oa-service/getAllDept.php");
  }
  //获取所有职位
  getAllPosition(): Observable<any> {
    return this.httpClient.get(this.root_url + "oa-service/getAllPosition.php");
  }
  //修改个人资料(人事管理)
  resetEmployeeInfo(id, dept, position): Observable<any> {
    let formdata = new FormData();
    formdata.append('id', id);
    formdata.append('dept', dept);
    formdata.append('position', position);
    return this.httpClient.post(this.root_url + "oa-service/resetEmployeeInfo.php", formdata);
  }

  //添加新员工
  getNewEmployee(name, sex, birth, phone, address, email, deptId, occId, salary): Observable<any> {
    let formdata = new FormData();
    formdata.append('name', name);
    formdata.append('sex', sex);
    formdata.append('birth', birth);
    formdata.append('phone', phone);
    formdata.append('address', address);
    formdata.append('email', email);
    formdata.append('deptId', deptId);
    formdata.append('occId', occId);
    formdata.append('salary', salary);
    return this.httpClient.post(this.root_url + "oa-service/insertEmployee.php", formdata);
  }

  //购物车

  getAllCart(id): Observable<any> {
    let formData = new FormData();
    formData.append('id', id);
    return this.httpClient.post(this.root_url + "oa-service/getAllCart.php", formData);
  }

  //请假提交
  inserVacate(empId, type, reason, startTime, endTime, days): Observable<any> {
    let formdata = new FormData();
    formdata.append("empId", empId);
    formdata.append("type", type);
    formdata.append("reason", reason);
    formdata.append("startTime", startTime);
    formdata.append("endTime", endTime);
    formdata.append("days", days);
    return this.httpClient.post(
      this.root_url + "oa-service/insertVacate.php",
      formdata
    );
  }

  //获取所有审批

  getAllApproval(state = null): Observable<any> {
    return this.httpClient.get(this.root_url + "oa-service/getAllApproval.php",
      {
        params: { state }
      }
    );
  }


  getKeyword(keyword): Observable<any> {
    return this.httpClient.get(this.root_url + "oa-service/getKeyword.php", { params: { keyword } });
  }

  //获取所有任务
  getAllTask(id): Observable<any> {
    let formdata = new FormData();
    formdata.append("id", id);
    return this.httpClient.post(
      this.root_url + "oa-service/getAllTask.php",
      formdata
    );
  }

  //修改任务状态
  updateTaskState(state, no): Observable<any> {
    let formdata = new FormData();
    formdata.append('state', state);
    formdata.append('no', no);
    return this.httpClient.post(this.root_url + "oa-service/updateTaskState.php", formdata);
  }
  //修改审批状态
  updateApproval(taskId, applicant, state, sign): Observable<any> {
    let formData = new FormData();
    formData.append("taskId", taskId);
    formData.append("applicant", applicant);
    formData.append("state", state);
    formData.append("sign", sign);
    return this.httpClient.post(
      this.root_url + "oa-service/updateApproval.php",
      formData
    );
  }
}
